#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
using namespace std;

int maxSubArray(vector<int>& nums) {
int ans = nums[0],sum=0;
for(auto temp:nums){
    if(sum>0){
        sum+=temp;
    }else{
        sum=temp;
    }
    ans=max(ans,sum);
}
    return ans;
}

int main(){
    vector<int>a={-2,1,-3,4,-1,2,1,-5,4};
    cout<<maxSubArray(a);
    return 0;
}